package servermain.auth.basic;

import java.util.HashMap;
import java.util.Map;

import javax.xml.ws.Endpoint;

import org.apache.cxf.jaxws.EndpointImpl;
import org.apache.cxf.ws.security.wss4j.WSS4JInInterceptor;
import org.apache.cxf.ws.security.wss4j.WSS4JOutInterceptor;
import org.springframework.context.support.AbstractApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.hysoft.cxf.ws.HelloWorld;

public class ServerMain {
	private static AbstractApplicationContext cxt;

	public static void main(String[] args) {
		cxt = new ClassPathXmlApplicationContext("cxf-application.xml");
		HelloWorld hw = (HelloWorld) cxt.getBean("helloWorldImpl");
		// 调用Endpoint的publish发布
		EndpointImpl ep = (EndpointImpl)Endpoint.publish("http://10.71.58.54:9999/hysoft", hw);
		Map<String, Object> outProps = new HashMap<String, Object>();
		outProps.put("action", "UsernameToken Timestamp");

		outProps.put("passwordType", "PasswordText");
		outProps.put("user", "Alice");
		outProps.put("passwordCallbackClass",
				"com.hysoft.cxf.ws.auth.basic.UTPasswordCallback");

		ep.getOutInterceptors().add(new WSS4JOutInterceptor(outProps));

		Map<String, Object> inProps = new HashMap<String, Object>();
		inProps.put("action", "UsernameToken Timestamp");
		inProps.put("passwordType", "PasswordDigest");
		inProps.put("passwordCallbackClass",
				"com.hysoft.cxf.ws.auth.basic.UTPasswordCallback");

		ep.getInInterceptors().add(new WSS4JInInterceptor(inProps));
		System.out.println("*****暴露成功*****");
	}
}
